<?php
/**
 * @author Demianchuk Dmitro
 * @email d.demianchuk@gmail.com
 * @date 05.01.12
 * @version 1.0
 * @package adminArea
 */
class MarkdownInput extends TextInput
{
	private function registerJsCss(){
		$markitup = Yii::app()->assetManager->publish(
			Yii::getPathOfAlias('ext.markitup'), true, -1, YII_DEBUG
		);
		Yii::app()->getClientScript()->registerScriptFile($markitup . '/jquery.markitup.js');
		Yii::app()->getClientScript()->registerScriptFile($markitup . '/sets/default/set.js');
		Yii::app()->getClientScript()->registerCssFile($markitup . '/skins/markitup/style.css');
		Yii::app()->getClientScript()->registerCssFile($markitup . '/sets/default/style.css');
	}

	public function show(){
		$this->registerJsCss();
		$value = '';
		if($this->itemId!=0){
			$value = $this->getData($this->current,$this->relationName);
		}
		return <<<TEXT
<span id="{$this->name}EnableEditor" class="button">Включить/Выключить редактор</span>
<div style="clear:both;"></div>
<textarea id="{$this->name}" name="_form[{$this->name}]">{$value}</textarea>
<script>
$(document).ready(function(){
	$('#{$this->name}EnableEditor').live('click',function() {
		$('#{$this->name}').markItUp(myMarkDownSettings);
		$(this).attr('id','{$this->name}DisableEditor');
	});
	$('#{$this->name}DisableEditor').live('click',function() {
		$('#{$this->name}').markItUpRemove();
		$(this).attr('id','{$this->name}EnableEditor');
	});
});
</script>
TEXT;
	}
}
